%==========================================================================
%=  This file is part of the Sound Restoration Project
%=  (c) Copyright Industrial Mathematics Institute
%=                University of South Carolina, Department of Mathematics
%=  ALL RIGHTS RESERVED
%=
%=  Author: Borislav Karaivanov
%==========================================================================

%==========================================================================
% List of the files on which this procedure depends:
%
% none
%
%==========================================================================

%==========================================================================
% The function "getSizeOf2DArrayFromFile" reads the dimensions of a 2D
% array of floats from a specified text file.
% INPUT: "fileName" is a string specifying the name of the text file to be
% read including a full directory path.
% OUTPUT: "numRows" and "numCols" return the number of rows and the number
% of columns of the 2D array stored in the given text file.
%==========================================================================
function [numRows, numCols] = getSizeOf2DArrayFromFile(fileName)

% Assert that the input file exists.
assert((exist(fileName, 'file') == 2), ...
    'SoundRestoration:getSizeOf2DArrayFromFile:InFileInexisting', ...
    'The file %s can not be found.', fileName);

% Open the file for reading.
fid = fopen(fileName, 'rt');

% Assert that the input file is open for reading text.
assert((fid ~= -1), ...
    'SoundRestoration:getSizeOf2DArrayFromFile:InFileCanNotBeRead', ...
    'The file %s can not be open for reading text.', fileName);

% Read in the desired patterns from the first two lines.
currLine = fgetl(fid);
numRows = sscanf(currLine, 'number of rows: %d\n');
currLine = fgetl(fid);
numCols = sscanf(currLine, 'number of columns: %d\n');

% Close the file.
fclose(fid);

return;
% end of the function "getSizeOf2DArrayFromFile"
